
<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
	<html:base />

	<title>makeQuestion.jsp</title>
	<script>
     var i=65;
     //调用此方法添加一行来添加一个选项.该方法会自动根据前面所生成的选项号自动增加A,B,C...
     function addRow(){
	if(i>90){//当选项到达'Z'时提醒用户无法继续添加选项
	window.alert("问题选项过多，无法再继续添加！");
return;
    }
     var str='<input type="text" length=50 '+" id=questionOption"+i+">";
     trd=document.all.question.insertRow();
     trd.insertCell().innerHTML=String.fromCharCode(i);
     trd.insertCell().innerHTML=str;
     trd.insertCell().innerHTML='<html:button property="entert" value="删除" onclick="deleteRow(this)"/>';
     i=i+1;
  }
  //删除一行时调用
  function deleteRow(tt){
     tt.parentNode.parentNode.removeNode(true);
	i=i-1;
  }
function obtainString(){
var optionStr="";
var questionContent="";
for(t=65;t<i;t++){
if(document.getElementById("questionOption"+t).value==""){
window.alert("选项"+String.fromCharCode(t)+"不能为空!");
return;
}
optionStr=optionStr+String.fromCharCode(t)+".";
questionContent=questionContent+document.getElementById("questionOption"+t).value+"a";
}
var subject=document.all.subject.value;
var answer=document.all.answer.value;
var subjectname=document.all.subjectName;
var subjectStr="";
for(i=0;i<subjectname.options.length;i++){
if(subjectname.options[i].selected){
subjectStr=subjectStr+subjectname.options[i].value+".";
   }
}
document.location.href="./enterQuestion.do?optionNumber="+optionStr+"&optionContent="+questionContent+"&subjectName="+subjectStr+"&answer="+answer+"&subject="+subject;
}
function cancel(){
document.location.href="./makeQuestion.do";
}
  </script>
</head>
<body topmargin="0" leftmargin="0">
	<DIV align="center">
		<html:form action="/enterQuestion">
			<ul>
				<bean:message key="enterQuestion.subjectType" />
				<html:select property="subjectName" multiple="true" size="8">
					<html:options collection="subjectTypes" property="name" />
				</html:select>
			</ul>
			<ul>
				<bean:message key="enterQuestion.subject" />
				<html:text property="subject" value=""></html:text>
			</ul>
			<ul>
				<bean:message key="enterQuestion.question" />
				<html:button property="addQuestionOption" onclick="addRow()">
					<bean:message key="button.addQuestionOption" />
				</html:button>
				<br>
				<table width="300" id="question">
				</table>
			</ul>
			<ul>
				<bean:message key="enterQuestion.answer" />
				<html:text property="answer" value="如为多选题，例：ABC" size="25" onmousedown="javascript:if (this.value=='如为多选题，例：ABC')this.value='';" />
			</ul>
			<ul>
				<html:button property="enter" onclick="obtainString()">
					<bean:message key="button.enterquestion.enter" />
				</html:button>
				<html:button property="enter" onclick="cancel()">
					<bean:message key="button.cancel" />
				</html:button>
			</ul>
			<ul>
				<logic:messagesPresent message="true">
					<html:messages id="errorMessage" message="true">
						<li>
							<font color="red"> <bean:write name="errorMessage" /></font>
						</li>
					</html:messages>
				</logic:messagesPresent>
			</ul>
		</html:form>
		<UL>
			<FONT color="red"><html:errors property="subject" /></FONT>
		</UL>
		<UL>
			<FONT color="red"><html:errors property="answer" /></FONT>
		</UL>
	</DIV>
</body>
</html:html>
